package org.excilys.training.ebanking.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "UTILISATEUR")
public class Utilisateur {
	// ATTRIBUT
	private int id;

	private String nom;
	private String login;
	private String password;
	private List<Autorisation> roles = new ArrayList<Autorisation>();
	private List<Compte> comptes = new ArrayList<Compte>();

	// GETTERS & SETTERS
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@ManyToMany()
	@JoinTable(name = "UTILISATEUR_AUTORISATION", joinColumns = @JoinColumn(name = "utilisateur_id"), inverseJoinColumns = @JoinColumn(name = "autorisation_id"))
	public List<Autorisation> getRoles() {
		return roles;
	}

	public void setRoles(List<Autorisation> roles) {
		this.roles = roles;
	}

	@ManyToMany(mappedBy = "clients")
	public List<Compte> getComptes() {
		return comptes;
	}

	public void setComptes(List<Compte> comptes) {
		this.comptes = comptes;
	}

}
